





var adCode = 110000;
    var depth = 2;
    var map = new AMap.Map("container", {
        zoom: 4.5,
        center: [116.412427, 39.303573],
        pitch: 0,
        viewMode: '3D',
    });

    // 创建省份图层
    var disProvince;
    function initPro(code, dep,level) {
        dep = typeof dep == 'undefined' ? 2 : dep;
        adCode = code;
        depth = dep;

        //disProvince && disProvince.setMap(null);

        disProvince = new AMap.DistrictLayer.Province({
            zIndex: 12,
            adcode: [code],
            depth: dep,
            styles: {
                'fill': function (properties) {
                    // properties为可用于做样式映射的字段，包含
                    // NAME_CHN:中文名称
                    // adcode_pro
                    // adcode_cit
                    // adcode
                    var adcode = properties.adcode;
                    return getColorByAdcode(adcode,level);
                },
                'province-stroke': 'cornflowerblue',
                'city-stroke': 'white', // 中国地级市边界
                'county-stroke': 'rgba(255,255,255,0.5)' // 中国区县边界
            }
        });

        disProvince.setMap(map);
    }

    // 颜色辅助方法
    var colors = {};
    var getColorByAdcode = function (adcode,intensity) {
      intensity = intensity || 1; // 默认为1，即不调整颜色深浅

      if (!colors[adcode]) {
        var intensityValue = 255 - Math.min(255, intensity * 20); // 根据 intensity 计算颜色深度
        colors[adcode] = 'rgb(' + intensityValue + ',0,0)'; // 设置红色，绿色和蓝色分量为0
    }

        return colors[adcode];
    };

    
    fetch(`/home/map`)
      .then(response => response.json())
      .then(jsonData => {
          if( jsonData && jsonData.length > 0){
            for (var i = 0; i < jsonData.length; i++) {
                var city = jsonData[i];
                console.log('城市adcode: ' + city.adcode);
                console.log('地震等级: ' + city.earthQuakeLevel);
                initPro(city.adcode,depth,city.earthQuakeLevel)
                console.log('---'); // 用于分隔不同城市的信息
            }
          }
          else{
            alert("error");
          }
      })
      .catch(error => {
          console.error("请求失败", error);
      });

document.addEventListener("DOMContentLoaded",function () {
    const returnback=document.getElementsByClassName('sidenav__brand')[0];
    returnback.addEventListener("click",function () {
        var main = document.getElementsByClassName('main')[0];
        location.reload();

    })
})









